﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WFNetLib.MyControls
{
    public class ToolStripDateTimePicker : ToolStripControlHost
    {
        public event EventHandler ValueChanged;
        public ToolStripDateTimePicker() 
            : base(new DateTimePicker())
        {

        }
        public ToolStripDateTimePicker(DateTime dt)
            : base(new DateTimePicker())
        {
            Control.Value = dt;
        }
        public new DateTimePicker Control 
        { 
            get 
            { 
                return (DateTimePicker)base.Control; 
            } 
        }
        //create a striong typed Value property
        public DateTime Value
        {
            get 
            { 
                return Control.Value; 
            }
        }

        protected override void OnSubscribeControlEvents(Control control)
        {
            base.OnSubscribeControlEvents(control);
            ((DateTimePicker)control).ValueChanged += new EventHandler(HandleValueChanged);
        }
    
        protected override void OnUnsubscribeControlEvents(Control control)
        {
            base.OnSubscribeControlEvents(control);
            ((DateTimePicker)control).ValueChanged -= new EventHandler(HandleValueChanged);
        }
        private void HandleValueChanged (object sender, EventArgs e)
        {
            if (ValueChanged != null)
                ValueChanged(this, e);
        }
    }
}

